# -*- coding: utf-8 -*-

from functools import lru_cache
from pydantic_settings import BaseSettings
from typing import List


class Settings(BaseSettings):
    # 调试模式
    APP_DEBUG: bool = True
    RELOAD: bool = True
    API_PREFIX: str = "/fastapi"
    # 项目信息
    VERSION: str = "0.0.1"
    PROJECT_NAME: str = "fasdapi"
    DESCRIPTION: str = '<a href="/fastapi/redoc" target="_blank">redoc</a>'
    # 跨域请求
    CORS_ORIGINS: List = ["*"]
    CORS_ALLOW_CREDENTIALS: bool = True
    CORS_ALLOW_METHODS: List = ["*"]
    CORS_ALLOW_HEADERS: List = ["*"]
    # Session
    SECRET_KEY: str = "session"
    SESSION_COOKIE: str = "session_id"
    SESSION_MAX_AGE: int = 14 * 24 * 60 * 60
    # Jwt
    JWT_SECRET_KEY: str = "09d25e094faa6ca2556c818166b7a9563b93f7099f6f0f4caa6cf63b88e8d3e7"
    JWT_ALGORITHM: str = "HS256"
    JWT_ACCESS_TOKEN_EXPIRE_MINUTES: int = 24 * 60
    JWT_REFRESH_TOKEN_EXPIRE_MINUTES: int = 7 * 24 * 60
    # openapi
    SWAGGER_UI_OPENAPI_URL: str = "/fastapi/openapi.json"
    SWAGGER_UI_DOCS_URL: str = "/fastapi/docs"
    SWAGGER_UI_REDOC_RL: str = "/fastapi/redoc"
    SWAGGER_UI_OAUTH2_REDIRECT_URL: str = "/fastapi/api/v1/auth/oauth2"
    # 数据库配置
    # DB_HOST: str = "127.0.0.1"
    # DB_PORT: int = 3306
    # DB_USER: str = "root"
    # DB_PASSWORD: str = "root"
    # DB_NAME: str = "test"
    DB_DSN: str = "mysql+pymysql://root:root@127.0.0.1:3306/test"
    DB_ECHO: bool = True 
    # email
    MAIL_USERNAME: str = "test@qq.com" # 邮箱账号
    MAIL_PASSWORD: str = "test" # 邮箱密码, 注意不是邮箱登录密码，而是授权码
    MAIL_FROM: str = "test@qq.com"  # 发送者邮箱, 注意不是邮箱账号
    MAIL_PORT: int = 465 # 邮箱端口, 587/465(SSL)
    MAIL_SERVER: str = "smtp.qq.com" # 邮箱服务器
    MAIL_SSL_TLS: bool = True # 是否使用SSL: 465
    MAIL_STARTTLS: bool = False # 是否使用TLS: 587
    USE_CREDENTIALS: bool = True # 是否使用认证
    VALIDATE_CERTS: bool = False # 是否验证证书
    # redis
    REDIS_HOST: str = "127.0.0.1"
    REDIS_PORT: int = 6379
    REDIS_PASSWORD: str = ""
    REDIS_DB: int = 0
    REDIS_ENCODING: str = "utf-8"
    REDIS_DECODE_RESPONSES: bool = True
    # admin_invite_code
    ADMIN_INVITE_CODE: str = "admin"
    class Config:
        # 设置需要识别的 .env 文件
        env_file = ".env"
        # 设置字符编码
        env_file_encoding = 'utf-8'

@lru_cache()
def get_settings():
    return Settings()


settings = get_settings()